using System;
using System.Security.Cryptography;


namespace Widgetsphere.Core.Util
{
	public enum CryptographyAlgorithm 
	{
		Des,
		Rc2,
		Rijndael, 
		TripleDes
	}

	public sealed partial class CryptoFactory
	{
		private CryptoFactory(){}

		#region Public Create Methods

		public static ICryptoHelper Create(CryptographyAlgorithm algorithm)
		{
			switch(algorithm)
			{
				case CryptographyAlgorithm.Des:
				case CryptographyAlgorithm.Rc2:
				case CryptographyAlgorithm.Rijndael:
				case CryptographyAlgorithm.TripleDes:
					return new SymmetricCryptographyHelper(algorithm);
				default:
				{
					throw new CryptographicException("Algorithm '" + 
						algorithm + 
						"' not supported.");
				}
			}
			
		}

		public static ICryptoHelper Create(CryptographyAlgorithm algorithm, string entropy)
		{
			switch(algorithm)
			{
				case CryptographyAlgorithm.Des:
				case CryptographyAlgorithm.Rc2:
				case CryptographyAlgorithm.Rijndael:
				case CryptographyAlgorithm.TripleDes:
					return new SymmetricCryptographyHelper(algorithm, entropy);
				default:
				{
					throw new CryptographicException("Algorithm '" + 
						algorithm + 
						"' not supported.");
				}
			}
		}

		public static ICryptoHelper Create(string algorithmName, string entropy)
		{
			CryptographyAlgorithm algorithm = (CryptographyAlgorithm)System.Enum.Parse(typeof(CryptographyAlgorithm), algorithmName, true);
			return Create(algorithm, entropy);
		}

		#endregion

	}
}

